﻿using FreeGoo.GameEngine;
using FreeGoo.GameEngine.Renderables;

namespace FreeGoo.GameEngine
{
    public class Rotator : IEngineScript
    {
        private Engine _engine;
        private BodyRenderable _rotator;
        private float _angle;
		private string _bodyNameToRotate;
				
        public Rotator(string bodyNameToRotate)
        {
			_bodyNameToRotate = bodyNameToRotate;
        }
		
		public static void RegisterEngineScripts(Engine engine)
		{
			engine.AddScript(new Rotator("Rotator"));
		}

        public void Prepare(Engine engine)
        {
            _engine = engine;
            _rotator = _engine.GetRenderableById(_bodyNameToRotate) as BodyRenderable;
        }

        public void UpdatePhysics()
        {
            _angle = _angle + 0.05f;
            _rotator.Body.Rotation = _angle;
        }

        public void Unprepare()
        {
        }
    }
}
